<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>小程序面试题 | 破破的QQ空间</title><meta name="author" content="破破"><meta name="copyright" content="破破"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="请谈谈微信小程序各个文件的作用 project.config.json 项目配置文件，用得最多的就是配置是否开启 https 校验； App.js 设置一些全局的基础数据等； App.json 底部 tab, 标题栏和路由等设置； App.wxss 公共样式，引入 iconfont 等； pages 里面包含一个个具体的页面； index.json (配置当前页面标题和引入组件等)； index.">
<meta property="og:type" content="article">
<meta property="og:title" content="小程序面试题">
<meta property="og:url" content="https://leiboy.gitee.io/blog/2022/07/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E9%9D%A2%E8%AF%95%E9%A2%98/index.html">
<meta property="og:site_name" content="破破的QQ空间">
<meta property="og:description" content="请谈谈微信小程序各个文件的作用 project.config.json 项目配置文件，用得最多的就是配置是否开启 https 校验； App.js 设置一些全局的基础数据等； App.json 底部 tab, 标题栏和路由等设置； App.wxss 公共样式，引入 iconfont 等； pages 里面包含一个个具体的页面； index.json (配置当前页面标题和引入组件等)； index.">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://leiboy.gitee.io/blog/2022/07/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E9%9D%A2%E8%AF%95%E9%A2%98/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%9B%BE%E6%A0%87.jpeg">
<meta property="article:published_time" content="2022-07-13T15:39:09.000Z">
<meta property="article:modified_time" content="2024-07-01T14:13:29.129Z">
<meta property="article:author" content="破破">
<meta property="article:tag" content="微信小程序">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://leiboy.gitee.io/blog/2022/07/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E9%9D%A2%E8%AF%95%E9%A2%98/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%9B%BE%E6%A0%87.jpeg"><link rel="shortcut icon" href="/blog/img/favicon.png"><link rel="canonical" href="https://leiboy.gitee.io/blog/2022/07/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E9%9D%A2%E8%AF%95%E9%A2%98/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blog/css/index.css?v=4.14.0-b3"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5.1/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0.35/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>(()=>{
      const saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
      
      window.btf = {
        saveToLocal: saveToLocal,
        getScript: (url, attr = {}) => new Promise((resolve, reject) => {
          const script = document.createElement('script')
          script.src = url
          script.async = true
          script.onerror = reject
          script.onload = script.onreadystatechange = function() {
            const loadState = this.readyState
            if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
            script.onload = script.onreadystatechange = null
            resolve()
          }

          Object.keys(attr).forEach(key => {
            script.setAttribute(key, attr[key])
          })

          document.head.appendChild(script)
        }),

        getCSS: (url, id = false) => new Promise((resolve, reject) => {
          const link = document.createElement('link')
          link.rel = 'stylesheet'
          link.href = url
          if (id) link.id = id
          link.onerror = reject
          link.onload = link.onreadystatechange = function() {
            const loadState = this.readyState
            if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
            link.onload = link.onreadystatechange = null
            resolve()
          }
          document.head.appendChild(link)
        }),

        addGlobalFn: (key, fn, name = false, parent = window) => {
          const pjaxEnable = false
          if (!pjaxEnable && key.startsWith('pjax')) return

          const globalFn = parent.globalFn || {}
          const keyObj = globalFn[key] || {}
    
          if (name && keyObj[name]) return
    
          name = name || Object.keys(keyObj).length
          keyObj[name] = fn
          globalFn[key] = keyObj
          parent.globalFn = globalFn
        }
      }
    
      const activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      const activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }

      btf.activateDarkMode = activateDarkMode
      btf.activateLightMode = activateLightMode
      
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })()</script><script>const GLOBAL_CONFIG = {
  root: '/blog/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false,"highlightFullpage":true,"highlightMacStyle":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid@4.11.1/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '小程序面试题',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-07-01 22:13:29'
}</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">10</div></a><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">7</div></a><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div><hr class="custom-hr"/></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/blog/2022/07/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E9%9D%A2%E8%AF%95%E9%A2%98/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%9B%BE%E6%A0%87.jpeg')"><nav id="nav"><span id="blog-info"><a href="/blog/" title="破破的QQ空间"><span class="site-name">破破的QQ空间</span></a></span><div id="menus"><div id="toggle-menu"><span class="site-page"><i class="fas fa-bars fa-fw"></i></span></div></div></nav><div id="post-info"><h1 class="post-title">小程序面试题</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-07-13T15:39:09.000Z" title="发表于 2022-07-13 23:39:09">2022-07-13</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-07-01T14:13:29.129Z" title="更新于 2024-07-01 22:13:29">2024-07-01</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blog/categories/%E9%9D%A2%E8%AF%95%E9%A2%98/">面试题</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="小程序面试题"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h3 id="请谈谈微信小程序各个文件的作用"><a href="#请谈谈微信小程序各个文件的作用" class="headerlink" title="请谈谈微信小程序各个文件的作用"></a>请谈谈微信小程序各个文件的作用</h3><ul>
<li>project.config.json 项目配置文件，用得最多的就是配置是否开启 https 校验；</li>
<li>App.js 设置一些全局的基础数据等；</li>
<li>App.json 底部 tab, 标题栏和路由等设置；</li>
<li>App.wxss 公共样式，引入 iconfont 等；</li>
<li>pages 里面包含一个个具体的页面；</li>
<li>index.json (配置当前页面标题和引入组件等)；</li>
<li>index.wxml (页面结构)；</li>
<li>index.wxss (页面样式表)；</li>
<li>index.js (页面的逻辑，请求和数据处理等)；</li>
</ul>
<h3 id="请谈谈-wxml-与标准的-html-的异同？"><a href="#请谈谈-wxml-与标准的-html-的异同？" class="headerlink" title="请谈谈 wxml 与标准的 html 的异同？"></a>请谈谈 wxml 与标准的 html 的异同？</h3><ul>
<li>都是用来描述页面的结构；</li>
<li>都有标签、属性等构成；</li>
<li>标签名字不一样，小程序的标签较少</li>
<li>多了一些 wx:if 这样的属性以及 <code>&#123;&#123; &#125;&#125;</code> 这样的表达式</li>
<li>小程序中无法使用 window 对象和 document 对象。</li>
</ul>
<h3 id="请谈谈-WXSS-和-CSS-的异同？"><a href="#请谈谈-WXSS-和-CSS-的异同？" class="headerlink" title="请谈谈 WXSS 和 CSS 的异同？"></a>请谈谈 WXSS 和 CSS 的异同？</h3><ul>
<li>都是用来描述页面的样子；</li>
<li>WXSS 具有 CSS 大部分的特性，也做了一些扩充和修改；</li>
<li>WXSS 新增了尺寸单位，WXSS 在底层支持新的尺寸单位 rpx；</li>
<li>WXSS 仅支持部分 CSS 选择器；</li>
<li>WXSS 提供全局样式与局部样式</li>
</ul>
<h3 id="你是怎么封装微信小程序的数据请求的？"><a href="#你是怎么封装微信小程序的数据请求的？" class="headerlink" title="你是怎么封装微信小程序的数据请求的？"></a>你是怎么封装微信小程序的数据请求的？</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> app = <span class="title function_">getApp</span>();</span><br><span class="line"><span class="comment">//项目URL相同部分，减轻代码量，同时方便项目迁移</span></span><br><span class="line"><span class="comment">//这里因为我是本地调试，所以host不规范，实际上应该是你备案的域名信息</span></span><br><span class="line"><span class="keyword">var</span> host = <span class="string">&quot;http://localhost:8081/demo/&quot;</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * POST请求，</span></span><br><span class="line"><span class="comment"> * URL：接口</span></span><br><span class="line"><span class="comment"> * postData：参数，json类型</span></span><br><span class="line"><span class="comment"> * doSuccess：成功的回调函数</span></span><br><span class="line"><span class="comment"> * doFail：失败的回调函数</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">request</span>(<span class="params">url, postData, doSuccess, doFail</span>) &#123;</span><br><span class="line">	wx.<span class="title function_">request</span>(&#123;</span><br><span class="line">		<span class="comment">//项目的真正接口，通过字符串拼接方式实现</span></span><br><span class="line">		<span class="attr">url</span>: host + url,</span><br><span class="line">		<span class="attr">header</span>: &#123;</span><br><span class="line">			<span class="string">&quot;content-type&quot;</span>: <span class="string">&quot;application/json;charset=UTF-8&quot;</span>,</span><br><span class="line">		&#125;,</span><br><span class="line">		<span class="attr">data</span>: postData,</span><br><span class="line">		<span class="attr">method</span>: <span class="string">&quot;POST&quot;</span>,</span><br><span class="line">		<span class="attr">success</span>: <span class="keyword">function</span> (<span class="params">res</span>) &#123;</span><br><span class="line">			<span class="comment">//参数值为res.data,直接将返回的数据传入</span></span><br><span class="line">			<span class="title function_">doSuccess</span>(res.<span class="property">data</span>);</span><br><span class="line">		&#125;,</span><br><span class="line">		<span class="attr">fail</span>: <span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">			<span class="title function_">doFail</span>();</span><br><span class="line">		&#125;,</span><br><span class="line">	&#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//GET请求，不需传参，直接URL调用，</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">getData</span>(<span class="params">url, doSuccess, doFail</span>) &#123;</span><br><span class="line">	wx.<span class="title function_">request</span>(&#123;</span><br><span class="line">		<span class="attr">url</span>: host + url,</span><br><span class="line">		<span class="attr">header</span>: &#123;</span><br><span class="line">			<span class="string">&quot;content-type&quot;</span>: <span class="string">&quot;application/json;charset=UTF-8&quot;</span>,</span><br><span class="line">		&#125;,</span><br><span class="line">		<span class="attr">method</span>: <span class="string">&quot;GET&quot;</span>,</span><br><span class="line">		<span class="attr">success</span>: <span class="keyword">function</span> (<span class="params">res</span>) &#123;</span><br><span class="line">			<span class="title function_">doSuccess</span>(res.<span class="property">data</span>);</span><br><span class="line">		&#125;,</span><br><span class="line">		<span class="attr">fail</span>: <span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">			<span class="title function_">doFail</span>();</span><br><span class="line">		&#125;,</span><br><span class="line">	&#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * module.exports用来导出代码</span></span><br><span class="line"><span class="comment"> * js文件中通过var call = require(&quot;../util/request.js&quot;)  加载</span></span><br><span class="line"><span class="comment"> * 在引入引入文件的时候&quot;  &quot;里面的内容通过../../../这种类型，小程序的编译器会自动提示，因为你可能</span></span><br><span class="line"><span class="comment"> * 项目目录不止一级，不同的js文件对应的工具类的位置不一样</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="variable language_">module</span>.<span class="property">exports</span>.<span class="property">request</span> = request;</span><br><span class="line"><span class="variable language_">module</span>.<span class="property">exports</span>.<span class="property">getData</span> = getData;</span><br></pre></td></tr></table></figure>

<h3 id="小程序页面间有哪些传递数据的方法？"><a href="#小程序页面间有哪些传递数据的方法？" class="headerlink" title="小程序页面间有哪些传递数据的方法？"></a>小程序页面间有哪些传递数据的方法？</h3><ul>
<li>使用全局变量实现数据传递</li>
<li>页面跳转或重定向时，使用 url 带参数传递数据</li>
<li>使用组件模板 template 传递参数</li>
<li>使用缓存传递参数</li>
</ul>
<h3 id="请谈谈小程序的双向绑定和-vue-的异同？"><a href="#请谈谈小程序的双向绑定和-vue-的异同？" class="headerlink" title="请谈谈小程序的双向绑定和 vue 的异同？"></a>请谈谈小程序的双向绑定和 vue 的异同？</h3><p>大体相同，但小程序直接 this.data 的属性是不可以同步到视图的，必须调用 this.setData()方法！</p>
<h3 id="请谈谈小程序的生命周期函数？"><a href="#请谈谈小程序的生命周期函数？" class="headerlink" title="请谈谈小程序的生命周期函数？"></a>请谈谈小程序的生命周期函数？</h3><ul>
<li>onLoad() 页面加载时触发，只会调用一次，可获取当前页面路径中的参数。</li>
<li>onShow() 页面显示&#x2F;切入前台时触发，一般用来发送数据请求；</li>
<li>onReady() 页面初次渲染完成时触发, 只会调用一次，代表页面已可和视图层进行交互。</li>
<li>onHide() 页面隐藏&#x2F;切入后台时触发, 如底部 tab 切换到其他页面或小程序切入后台等。</li>
<li>onUnload() 页面卸载时触发，如 redirectTo 或 navigateBack 到其他页面时。</li>
<li>onPullDownRefresh() 下拉刷新的钩子函数 用户下拉刷新时会自动走到这个函数中</li>
<li>onReachBottom() 上翻到底的钩子函数</li>
</ul>
<h3 id="程序关联微信公众号如何确定用户的唯一性？"><a href="#程序关联微信公众号如何确定用户的唯一性？" class="headerlink" title="程序关联微信公众号如何确定用户的唯一性？"></a>程序关联微信公众号如何确定用户的唯一性？</h3><p>使用 wx.getUserInfo 方法 withCredentials 为 true 时，可获取 encryptedData，里面有 union_id.后端需要进行对称解密</p>
<h3 id="小程序调用后台接口遇到哪些问题？"><a href="#小程序调用后台接口遇到哪些问题？" class="headerlink" title="小程序调用后台接口遇到哪些问题？"></a>小程序调用后台接口遇到哪些问题？</h3><p>数据的大小限制，超过范围会直接导致整个小程序崩溃，除非重启小程序；</p>
<p>小程序不可以直接渲染文章内容这类型的 html 文本，显示需借助插件</p>
<h3 id="微信小程序如何实现下拉刷新？"><a href="#微信小程序如何实现下拉刷新？" class="headerlink" title="微信小程序如何实现下拉刷新？"></a>微信小程序如何实现下拉刷新？</h3><p>设置 onPullDownRefresh 函数实现</p>
<h3 id="webview-中的页面怎么跳转回小程序？"><a href="#webview-中的页面怎么跳转回小程序？" class="headerlink" title="webview 中的页面怎么跳转回小程序？"></a>webview 中的页面怎么跳转回小程序？</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">wx.<span class="property">miniProgram</span>.<span class="title function_">navigateTo</span>(&#123;</span><br><span class="line">	<span class="attr">url</span>:’pages/login/login’+’$params’</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line">**<span class="comment">//跳转到小程序导航页面**</span></span><br><span class="line"></span><br><span class="line">wx.<span class="property">miniProgram</span>.<span class="title function_">switchTab</span>(&#123;</span><br><span class="line">	<span class="attr">url</span>:’/pages/index/index’</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<h3 id="bindtap-和-catchtap-的区别？"><a href="#bindtap-和-catchtap-的区别？" class="headerlink" title="bindtap 和 catchtap 的区别？"></a>bindtap 和 catchtap 的区别？</h3><p>相同点：首先他们都是作为点击事件函数，就是点击时触发。在这个作用上他们是一样的，可以不做区分</p>
<p>不同点：他们的不同点主要是 bindtap 是不会阻止冒泡事件的，catchtap 是阻值冒泡的</p>
<h3 id="简述五个路由的区别"><a href="#简述五个路由的区别" class="headerlink" title="简述五个路由的区别"></a>简述五个路由的区别</h3><ul>
<li>wx.navigateTo()：保留当前页面，跳转到应用内的某个页面。但是不能跳到 tabbar 页面</li>
<li>wx.redirectTo()：关闭当前页面，跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面</li>
<li>wx.switchTab()：跳转到 tabBar 页面，并关闭其他所有非 tabBar 页面</li>
<li>wx.navigateBack()关闭当前页面，返回上一页面或多级页面。可通过 getCurrentPages() 获取当前的页面栈，决定需要返回几层</li>
<li>wx.reLaunch()：关闭所有页面，打开到应用内的某个页面</li>
</ul>
<h3 id="如何实现登录数据的持久化"><a href="#如何实现登录数据的持久化" class="headerlink" title="如何实现登录数据的持久化 ?"></a>如何实现登录数据的持久化 ?</h3><p>可以通过 wx.setStorageSync(‘键名’, 对应的值)来进行数据持久化</p>
<h3 id="微信支付的-流程是否可以简单说一下？"><a href="#微信支付的-流程是否可以简单说一下？" class="headerlink" title="微信支付的 流程是否可以简单说一下？"></a>微信支付的 流程是否可以简单说一下？</h3><p>临时凭证 获取 wxid<br>生成 repayid<br>json，返回给小程序，小程序调支付窗口。<br>支持成功提示 + POST 回调。</p>
<h3 id="wx-navigateTo-无法打开页面"><a href="#wx-navigateTo-无法打开页面" class="headerlink" title="wx.navigateTo 无法打开页面"></a>wx.navigateTo 无法打开页面</h3><p>一个应用同时只能打开 5 个页面，请避免多层级的交互方式，或使用 wx.redirectTo</p>
<h3 id="小程序有没有类似于-axios-的拦截器？"><a href="#小程序有没有类似于-axios-的拦截器？" class="headerlink" title="小程序有没有类似于 axios 的拦截器？"></a>小程序有没有类似于 axios 的拦截器？</h3><p>请求拦截器 addInterceptor</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://leiboy.gitee.io/blog">破破</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://leiboy.gitee.io/blog/2022/07/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E9%9D%A2%E8%AF%95%E9%A2%98/">https://leiboy.gitee.io/blog/2022/07/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E9%9D%A2%E8%AF%95%E9%A2%98/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://leiboy.gitee.io/blog" target="_blank">破破的QQ空间</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/blog/tags/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F/">微信小程序</a></div><div class="post_share"><div class="social-share" data-image="/blog/2022/07/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E9%9D%A2%E8%AF%95%E9%A2%98/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%9B%BE%E6%A0%87.jpeg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1.1.3/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1.1.3/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/2022/08/02/useContext%E6%A8%A1%E6%8B%9Fredux/" title="useContext模拟redux"><img class="cover" src="/blog/2022/08/02/useContext%E6%A8%A1%E6%8B%9Fredux/react-logo.png" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">useContext模拟redux</div></div></a></div><div class="next-post pull-right"><a href="/blog/2022/07/10/HTML%E5%92%8CCSS%E9%9D%A2%E8%AF%95%E9%A2%98/" title="HTML和CSS面试题"><img class="cover" src="/blog/2022/07/10/HTML%E5%92%8CCSS%E9%9D%A2%E8%AF%95%E9%A2%98/csslogo.png" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">HTML和CSS面试题</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">破破</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">10</div></a><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">7</div></a><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AF%B7%E8%B0%88%E8%B0%88%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%90%84%E4%B8%AA%E6%96%87%E4%BB%B6%E7%9A%84%E4%BD%9C%E7%94%A8"><span class="toc-number">1.</span> <span class="toc-text">请谈谈微信小程序各个文件的作用</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AF%B7%E8%B0%88%E8%B0%88-wxml-%E4%B8%8E%E6%A0%87%E5%87%86%E7%9A%84-html-%E7%9A%84%E5%BC%82%E5%90%8C%EF%BC%9F"><span class="toc-number">2.</span> <span class="toc-text">请谈谈 wxml 与标准的 html 的异同？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AF%B7%E8%B0%88%E8%B0%88-WXSS-%E5%92%8C-CSS-%E7%9A%84%E5%BC%82%E5%90%8C%EF%BC%9F"><span class="toc-number">3.</span> <span class="toc-text">请谈谈 WXSS 和 CSS 的异同？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%A0%E6%98%AF%E6%80%8E%E4%B9%88%E5%B0%81%E8%A3%85%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F%E7%9A%84%E6%95%B0%E6%8D%AE%E8%AF%B7%E6%B1%82%E7%9A%84%EF%BC%9F"><span class="toc-number">4.</span> <span class="toc-text">你是怎么封装微信小程序的数据请求的？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%A8%8B%E5%BA%8F%E9%A1%B5%E9%9D%A2%E9%97%B4%E6%9C%89%E5%93%AA%E4%BA%9B%E4%BC%A0%E9%80%92%E6%95%B0%E6%8D%AE%E7%9A%84%E6%96%B9%E6%B3%95%EF%BC%9F"><span class="toc-number">5.</span> <span class="toc-text">小程序页面间有哪些传递数据的方法？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AF%B7%E8%B0%88%E8%B0%88%E5%B0%8F%E7%A8%8B%E5%BA%8F%E7%9A%84%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%92%8C-vue-%E7%9A%84%E5%BC%82%E5%90%8C%EF%BC%9F"><span class="toc-number">6.</span> <span class="toc-text">请谈谈小程序的双向绑定和 vue 的异同？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AF%B7%E8%B0%88%E8%B0%88%E5%B0%8F%E7%A8%8B%E5%BA%8F%E7%9A%84%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E5%87%BD%E6%95%B0%EF%BC%9F"><span class="toc-number">7.</span> <span class="toc-text">请谈谈小程序的生命周期函数？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%A8%8B%E5%BA%8F%E5%85%B3%E8%81%94%E5%BE%AE%E4%BF%A1%E5%85%AC%E4%BC%97%E5%8F%B7%E5%A6%82%E4%BD%95%E7%A1%AE%E5%AE%9A%E7%94%A8%E6%88%B7%E7%9A%84%E5%94%AF%E4%B8%80%E6%80%A7%EF%BC%9F"><span class="toc-number">8.</span> <span class="toc-text">程序关联微信公众号如何确定用户的唯一性？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%A8%8B%E5%BA%8F%E8%B0%83%E7%94%A8%E5%90%8E%E5%8F%B0%E6%8E%A5%E5%8F%A3%E9%81%87%E5%88%B0%E5%93%AA%E4%BA%9B%E9%97%AE%E9%A2%98%EF%BC%9F"><span class="toc-number">9.</span> <span class="toc-text">小程序调用后台接口遇到哪些问题？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E4%B8%8B%E6%8B%89%E5%88%B7%E6%96%B0%EF%BC%9F"><span class="toc-number">10.</span> <span class="toc-text">微信小程序如何实现下拉刷新？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#webview-%E4%B8%AD%E7%9A%84%E9%A1%B5%E9%9D%A2%E6%80%8E%E4%B9%88%E8%B7%B3%E8%BD%AC%E5%9B%9E%E5%B0%8F%E7%A8%8B%E5%BA%8F%EF%BC%9F"><span class="toc-number">11.</span> <span class="toc-text">webview 中的页面怎么跳转回小程序？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#bindtap-%E5%92%8C-catchtap-%E7%9A%84%E5%8C%BA%E5%88%AB%EF%BC%9F"><span class="toc-number">12.</span> <span class="toc-text">bindtap 和 catchtap 的区别？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%AE%80%E8%BF%B0%E4%BA%94%E4%B8%AA%E8%B7%AF%E7%94%B1%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-number">13.</span> <span class="toc-text">简述五个路由的区别</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E7%99%BB%E5%BD%95%E6%95%B0%E6%8D%AE%E7%9A%84%E6%8C%81%E4%B9%85%E5%8C%96"><span class="toc-number">14.</span> <span class="toc-text">如何实现登录数据的持久化 ?</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BE%AE%E4%BF%A1%E6%94%AF%E4%BB%98%E7%9A%84-%E6%B5%81%E7%A8%8B%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E7%AE%80%E5%8D%95%E8%AF%B4%E4%B8%80%E4%B8%8B%EF%BC%9F"><span class="toc-number">15.</span> <span class="toc-text">微信支付的 流程是否可以简单说一下？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#wx-navigateTo-%E6%97%A0%E6%B3%95%E6%89%93%E5%BC%80%E9%A1%B5%E9%9D%A2"><span class="toc-number">16.</span> <span class="toc-text">wx.navigateTo 无法打开页面</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%A8%8B%E5%BA%8F%E6%9C%89%E6%B2%A1%E6%9C%89%E7%B1%BB%E4%BC%BC%E4%BA%8E-axios-%E7%9A%84%E6%8B%A6%E6%88%AA%E5%99%A8%EF%BC%9F"><span class="toc-number">17.</span> <span class="toc-text">小程序有没有类似于 axios 的拦截器？</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/2023/03/18/React%E6%A8%A1%E6%8B%9F%E7%A7%BB%E5%85%A5title%E6%8F%90%E7%A4%BA/" title="React模拟移入title提示"><img src="/blog/2023/03/18/React%E6%A8%A1%E6%8B%9F%E7%A7%BB%E5%85%A5title%E6%8F%90%E7%A4%BA/react-logo.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="React模拟移入title提示"/></a><div class="content"><a class="title" href="/blog/2023/03/18/React%E6%A8%A1%E6%8B%9F%E7%A7%BB%E5%85%A5title%E6%8F%90%E7%A4%BA/" title="React模拟移入title提示">React模拟移入title提示</a><time datetime="2023-03-18T14:58:49.000Z" title="发表于 2023-03-18 22:58:49">2023-03-18</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2023/03/08/React%E9%AB%98%E9%98%B6%E7%BB%84%E4%BB%B6%E6%9C%89%E5%93%AA%E4%BA%9B%E4%BC%98%E7%82%B9%E5%92%8C%E7%BC%BA%E7%82%B9/" title="React高阶组件有哪些优点和缺点"><img src="/blog/2023/03/08/React%E9%AB%98%E9%98%B6%E7%BB%84%E4%BB%B6%E6%9C%89%E5%93%AA%E4%BA%9B%E4%BC%98%E7%82%B9%E5%92%8C%E7%BC%BA%E7%82%B9/react-logo.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="React高阶组件有哪些优点和缺点"/></a><div class="content"><a class="title" href="/blog/2023/03/08/React%E9%AB%98%E9%98%B6%E7%BB%84%E4%BB%B6%E6%9C%89%E5%93%AA%E4%BA%9B%E4%BC%98%E7%82%B9%E5%92%8C%E7%BC%BA%E7%82%B9/" title="React高阶组件有哪些优点和缺点">React高阶组件有哪些优点和缺点</a><time datetime="2023-03-08T14:58:49.000Z" title="发表于 2023-03-08 22:58:49">2023-03-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2022/08/02/useContext%E6%A8%A1%E6%8B%9Fredux/" title="useContext模拟redux"><img src="/blog/2022/08/02/useContext%E6%A8%A1%E6%8B%9Fredux/react-logo.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="useContext模拟redux"/></a><div class="content"><a class="title" href="/blog/2022/08/02/useContext%E6%A8%A1%E6%8B%9Fredux/" title="useContext模拟redux">useContext模拟redux</a><time datetime="2022-08-02T14:58:49.000Z" title="发表于 2022-08-02 22:58:49">2022-08-02</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2022/07/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E9%9D%A2%E8%AF%95%E9%A2%98/" title="小程序面试题"><img src="/blog/2022/07/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E9%9D%A2%E8%AF%95%E9%A2%98/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%9B%BE%E6%A0%87.jpeg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="小程序面试题"/></a><div class="content"><a class="title" href="/blog/2022/07/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E9%9D%A2%E8%AF%95%E9%A2%98/" title="小程序面试题">小程序面试题</a><time datetime="2022-07-13T15:39:09.000Z" title="发表于 2022-07-13 23:39:09">2022-07-13</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2022/07/10/HTML%E5%92%8CCSS%E9%9D%A2%E8%AF%95%E9%A2%98/" title="HTML和CSS面试题"><img src="/blog/2022/07/10/HTML%E5%92%8CCSS%E9%9D%A2%E8%AF%95%E9%A2%98/csslogo.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="HTML和CSS面试题"/></a><div class="content"><a class="title" href="/blog/2022/07/10/HTML%E5%92%8CCSS%E9%9D%A2%E8%AF%95%E9%A2%98/" title="HTML和CSS面试题">HTML和CSS面试题</a><time datetime="2022-07-10T14:22:28.000Z" title="发表于 2022-07-10 22:22:28">2022-07-10</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2024 By 破破</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/blog/js/utils.js?v=4.14.0-b3"></script><script src="/blog/js/main.js?v=4.14.0-b3"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0.35/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"><script>(() => {
  const runMermaid = (ele) => {
    window.loadMermaid = true
    const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'default'

    Array.from(ele).forEach((item, index) => {
      const mermaidSrc = item.firstElementChild
      const mermaidThemeConfig = '%%{init:{ \'theme\':\'' + theme + '\'}}%%\n'
      const mermaidID = 'mermaid-' + index
      const mermaidDefinition = mermaidThemeConfig + mermaidSrc.textContent

      const renderFn = mermaid.render(mermaidID, mermaidDefinition)

      const renderV10 = () => {
        renderFn.then(({svg}) => {
          mermaidSrc.insertAdjacentHTML('afterend', svg)
        })
      }

      const renderV9 = svg => {
        mermaidSrc.insertAdjacentHTML('afterend', svg)
      }

      typeof renderFn === 'string' ? renderV9(renderFn) : renderV10()
    })
  }

  const codeToMermaid = () => {
    const codeMermaidEle = document.querySelectorAll('pre > code.mermaid')
    if (codeMermaidEle.length === 0) return
    
    codeMermaidEle.forEach(ele => {
      const newEle = document.createElement('div')
      newEle.className = 'mermaid-wrap'
      newEle.innerHTML = `<pre class="mermaid-src" hidden>${ele.textContent}</pre>`
      ele.parentNode.replaceWith(newEle)
    })
  }

  const loadMermaid = () => {
    if (false) codeToMermaid()
    const $mermaid = document.querySelectorAll('#article-container .mermaid-wrap')
    if ($mermaid.length === 0) return

    const runMermaidFn = () => runMermaid($mermaid)
    btf.addGlobalFn('themeChange', runMermaidFn, 'mermaid')
    window.loadMermaid ? runMermaidFn() : btf.getScript('https://cdn.jsdelivr.net/npm/mermaid@10.9.0/dist/mermaid.min.js').then(runMermaidFn)
  }
  
  btf.addGlobalFn('encrypt', loadMermaid, 'mermaid')
  window.pjax ? loadMermaid() : document.addEventListener('DOMContentLoaded', loadMermaid)
})()</script></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>